-
Notifications
You must be signed in to change notification settings - Fork 11.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
StandardToken encapsulation #1197
Conversation
emit Mint(_to, _amount); | ||
emit Transfer(address(0), _to, _amount); | ||
_mint(_to, _amount); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the event be emitted after the action took place, according to our guideline?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes. I initially did it like this because the test was relying on the previous order: Mint
followed by Transfer
. I'll fix the test.
Addressed previous comments and added tests for the new functions. @nventuro Please review again! 🙂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed you skipped some of the require
s for which we already have corresponding ones (e.g. transferFrom
and burnFrom
), leaving SafeMath
as the only line of defense. Is this something we want to do?
|
||
balances[_who] = balances[_who].sub(_value); | ||
totalSupply_ = totalSupply_.sub(_value); | ||
super._burn(_who, _value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is confusing: the public
burn
function calls the internal
_burn
function, which then calls super._burn
and emits an event. Why not remove the internal _burn
and just call base function from the public one?
edit: you did it right in the mint
function, so I'm assuming this wasn't intentional :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did this because both burn
and burnFrom
need to add the Burn
event. I felt it was better than adding the event in both. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's even worse now that I realize it lol. burnFrom
calls _burnFrom
, which calls the overriden _burn
, which calls the original burn
: unless you know the details of StandardToken
, you can't tell that burnFrom
will emit a Burn
event. The reason why you did it makes sense though.
I think the problem is the missing comment: if the overridden function said something like 'adds the Burn event when burning', it may read more clearly.
* @param _amount The amount that will be created. | ||
*/ | ||
function _mint(address _account, uint256 _amount) internal { | ||
totalSupply_ = totalSupply_.add(_amount); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Input validation on amount > 0
and account != 0
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_amount > 0
is a validation that we have decided in the past to not do, because it forces users of the function to special-case amount == 0
to avoid triggering a revert.
_account != 0
I guess we should add.
* @param _amount The amount that will be burnt. | ||
*/ | ||
function _burn(address _account, uint256 _amount) internal { | ||
totalSupply_ = totalSupply_.sub(_amount); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Input validation on amount > 0
, account != 0
, and balances[account] > amount
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about balances[account] > amount
. I thought we were using SafeMath
for this kind of thing, now that it uses require
.
Is this something we want to do?
I'm not sure.
function _burnFrom(address _account, uint256 _amount) internal { | ||
// Should https://github.com/OpenZeppelin/zeppelin-solidity/issues/707 be accepted, | ||
// this function needs to emit an event with the updated approval. | ||
allowed[_account][msg.sender] = allowed[_account][msg.sender].sub(_amount); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Input validation on amount > 0
, account != 0
, balances[account] > amount
and allowance[acount][msg.sender] > amount
?
Are you sure you want to declare |
@barakman if the variables are |
@nventuro Fixed new comments. I added in all the checks for balance and allowance, though I'd consider removing all those in a different issue. I'm requesting another review since this is a breaking change. |
* @param _amount The amount that will be burnt. | ||
*/ | ||
function _burnFrom(address _account, uint256 _amount) internal { | ||
require(_account != 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line and the last require are duplicate assertions since we're falling back to _burn
. Would save some gas, presumably, if we omit them but mention this in a comment.
const mintEvent = expectEvent.inLogs(logs, 'Mint', { | ||
to: owner, | ||
}); | ||
mintEvent.args.amount.should.be.bignumber.equal(amount); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can actually put that in the args object as well:
const mintEvent = expectEvent.inLogs(logs, 'Mint', {
to: owner,
amount,
});
and it will do the bignumber equals check. likewise below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I totally never merged that change 😢. I guess this can be refactoring
back in a later PR.
…On Wed, Aug 15, 2018, 12:09 Francisco Giordano ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In test/token/ERC20/MintableToken.behavior.js
<#1197 (comment)>
:
> @@ -104,11 +107,16 @@ function shouldBehaveLikeMintableToken (owner, minter, [anyone]) {
it('emits a mint and a transfer event', async function () {
const { logs } = await this.token.mint(owner, amount, { from });
- logs.length.should.eq(2);
- logs[0].event.should.eq('Mint');
- logs[0].args.to.should.eq(owner);
- logs[0].args.amount.should.be.bignumber.equal(amount);
- logs[1].event.should.eq('Transfer');
+ const mintEvent = expectEvent.inLogs(logs, 'Mint', {
+ to: owner,
+ });
+ mintEvent.args.amount.should.be.bignumber.equal(amount);
Are you sure about this? The code code for the helper looks like it uses
JavaScript's equality operator.
https://github.com/OpenZeppelin/openzeppelin-solidity/blob/8d11dcc0e5fb0fd50e018d7786750fa45e54d4c5/test/helpers/expectEvent.js#L6-L9
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub
<#1197 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABdsGbUz9WhLz_57yBks8NNHm-h8o83dks5uRHHkgaJpZM4V5req>
.
|
Addressed all comments! Can I get a ✔️? 😬 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you double check CappedToken.behavior.js
? It looks like there may be whitespace changes on that one (probably the line endings).
51ca533
to
24cb9cf
Compare
@nventuro You were right. I had to force push that last merge commit which dismissed the reviews. |
Fixes #1097.
Fixes #1208.
Makes all state variables of
StandardToken
private, and adds internal functions to modify them correctly emitting events.